import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

/// 提示弹框

class CenterTipsAlterWidget extends StatefulWidget {
  Function confirmCallback;
  String title;
  String desText;

  CenterTipsAlterWidget(this.confirmCallback, this.desText, this.title,
      {Key? key})
      : super(key: key);

  @override
  State<CenterTipsAlterWidget> createState() {
    return _CenterTipsAlterWidgetState();
  }
}

class _CenterTipsAlterWidgetState extends State<CenterTipsAlterWidget> {
  @override
  Widget build(BuildContext context) {
    return CupertinoAlertDialog(
      title: Text(widget.title),
      content: Column(
        children: [
          SizedBox(
            height: 10,
          ),
          Align(
            child: Text(widget.desText),
            alignment: Alignment(0, 0),
          )
        ],
      ),
      actions: [
        CupertinoDialogAction(
          child: const Text('取消'),
          onPressed: () {
            Navigator.pop(context);
          },
        ),
        CupertinoDialogAction(
          child: const Text('确定'),
          onPressed: () {
            widget.confirmCallback();
            Navigator.pop(context);
          },
        )
      ],
    );
  }
}

class BottomCustomAlterWidget extends StatefulWidget {
  final confirmCallback;

  final title;

  final option1;

  final option2;
  BottomCustomAlterWidget(
      this.confirmCallback, this.title, this.option1, this.option2,
      {Key? key})
      : super(key: key);

  @override
  State<BottomCustomAlterWidget> createState() =>
      _BottomCustomAlterWidgetState();
}

class _BottomCustomAlterWidgetState extends State<BottomCustomAlterWidget> {
  final controller = TextEditingController();
  @override
  Widget build(BuildContext context) {
    return CupertinoActionSheet(
      ///底部弹出的提示框

      title: Text(
        widget.title,
        style: TextStyle(fontSize: 22),
      ),

      actions: [
        CupertinoActionSheetAction(
            onPressed: () {
              Navigator.pop(context);
              widget.confirmCallback(widget.option1);
            },
            child: Text(widget.option1)),
        CupertinoActionSheetAction(
            onPressed: () {
              Navigator.pop(context);

              widget.confirmCallback(widget.option2);
            },
            child: Text(widget.option2)),
      ],

      cancelButton: CupertinoActionSheetAction(
        onPressed: () {
          Navigator.pop(context);
        },
        child: Text('取消'),
      ),
    );
  }
}

class ShowInputAlertWidget extends StatefulWidget {
  final confirmCallback;
  final title;
  final placeholder;

  ShowInputAlertWidget(this.confirmCallback, this.title, this.placeholder,
      {Key? key})
      : super(key: key);

  @override
  State<ShowInputAlertWidget> createState() => _ShowInputAlertWidgetState();
}

class _ShowInputAlertWidgetState extends State<ShowInputAlertWidget> {
  String inputValue = '';
  @override
  Widget build(BuildContext context) {
    return CupertinoAlertDialog(
      title: Text(widget.title),
      content: Column(
        children: [
          CupertinoTextField(
            placeholder: widget.placeholder,
            onChanged: (value) {
              inputValue = value;
            },
          )
        ],
      ),
      actions: [
        CupertinoDialogAction(
          child: Text('取消'),
          onPressed: () {
            Navigator.pop(context);
          },
        ),
        CupertinoDialogAction(
          child: Text('确定'),
          onPressed: () {
            widget.confirmCallback(inputValue);
          },
        )
      ],
    );
  }
}

class StyleDialog extends StatefulWidget {
  final confirmCallback;

  final title;

  final contentTitle;
  StyleDialog(this.confirmCallback, this.title, this.contentTitle, {Key? key})
      : super(key: key);

  @override
  State<StyleDialog> createState() => _StyleDialogState();
}

class _StyleDialogState extends State<StyleDialog> {
  @override
  Widget build(BuildContext context) {
    return SimpleDialog(
      titlePadding: EdgeInsets.only(top: 15, bottom: 5),
      title: Center(
        child: Text(widget.title),
      ),
      backgroundColor: Colors.white,
      shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
      children: [
        Divider(
          height: 1,
        ),
        Container(
          alignment: Alignment.center,
          height: 80,
          child: Text(widget.contentTitle,
              style: TextStyle(fontSize: 17, color: Colors.black)),
        ),
        Container(
            child: Row(
          children: [
            Expanded(
              flex: 2,
              child: ElevatedButton(
                onPressed: () {
                  Navigator.pop(context);
                },
                child: Container(
                  alignment: Alignment.center,
                  height: 50,
                  decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(10),
                    color: Colors.white,
                    border: Border.all(color: Color(0xffFF4B38), width: 1),
                  ),
                  child: Text('否',
                      style: TextStyle(color: Color(0xffFF4B38), fontSize: 17)),
                ),
              ),
            ),
            Expanded(
                flex: 3,
                child: TextButton(
                    onPressed: () {
                      widget.confirmCallback('');

                      Navigator.pop(context);
                    },
                    child: Container(
                      alignment: Alignment.center,
                      height: 50,
                      decoration: BoxDecoration(
                        borderRadius: BorderRadius.circular(10),

                        color: Color(0xffFF4B38),

                        // border: Border.all(color: Color(0xffFF4B38),width: 1),
                      ),
                      child: Text('是',
                          style: TextStyle(color: Colors.white, fontSize: 17)),
                    )))
          ],
        ))
      ],
    );
  }
}

class ShowDefineAlertWidget extends StatefulWidget {
  final confirmCallback;

  final title;

  final hintText;
  ShowDefineAlertWidget(this.confirmCallback, this.title, this.hintText,
      {Key? key})
      : super(key: key);

  @override
  State<ShowDefineAlertWidget> createState() => _ShowDefineAlertWidgetState();
}

class _ShowDefineAlertWidgetState extends State<ShowDefineAlertWidget> {
  @override
  Widget build(BuildContext context) {
    var _dialogWidth = MediaQuery.of(context).size.width * 0.86;
    return SimpleDialog(
      title: Column(
        children: [
          Padding(
            padding: EdgeInsets.only(bottom: 10),
            child: Text(widget.title,
                style: TextStyle(
                    color: Colors.black,
                    fontSize: 20,
                    fontWeight: FontWeight.w100)),
          ),
          Text(widget.hintText,
              style: TextStyle(
                  color: Colors.black,
                  fontSize: 18,
                  fontWeight: FontWeight.w100)),
        ],
      ),
      titlePadding: EdgeInsets.fromLTRB(10, 20, 10, 20),
      contentPadding: EdgeInsets.zero,
      children: [
        Divider(
          height: 1,
        ),
        ElevatedButton(
            onPressed: () {
              ///widget.confirmCallback('');
              ///这里设置回拨，不知道上面这个表达式什么意思，所以先转成注释了
              Navigator.pop(context);
            },
            child: Container(
              width: _dialogWidth,
              height: 40,
              alignment: Alignment.center,
              child: Text(
                "好的",
                style: TextStyle(color: Colors.white, fontSize: 18),
              ),
            )),
      ],
    );
  }
}
